package com.ruoyi.hospital.controller.storeInfo;

import java.util.List;

import com.ruoyi.common.utils.StringUtils;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hospital.domain.storeInfo.PharmacyDrug;
import com.ruoyi.hospital.service.storeInfo.IPharmacyDrugService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 药品信息Controller
 * 
 * @author wendao
 * @date 2024-08-19
 */
@RestController
@RequestMapping("/hospital/pharmacyDrug")
public class PharmacyDrugController extends BaseController
{
    @Autowired
    private IPharmacyDrugService pharmacyDrugService;

    /**
     * 查询药品信息列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:pharmacyDrug:list')")
    @GetMapping("/list")
    public TableDataInfo list(PharmacyDrug pharmacyDrug)
    {
        startPage();
        List<PharmacyDrug> list = pharmacyDrugService.selectPharmacyDrugList(pharmacyDrug);
        return getDataTable(list);
    }

    /**
     * 导出药品信息列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:pharmacyDrug:export')")
    @Log(title = "药品信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PharmacyDrug pharmacyDrug)
    {
        List<PharmacyDrug> list = pharmacyDrugService.selectPharmacyDrugList(pharmacyDrug);
        ExcelUtil<PharmacyDrug> util = new ExcelUtil<PharmacyDrug>(PharmacyDrug.class);
        util.exportExcel(response, list, "药品信息数据");
    }

    /**
     * 获取药品信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:pharmacyDrug:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(pharmacyDrugService.selectPharmacyDrugById(id));
    }

    /**
     * 新增药品信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:pharmacyDrug:add')")
    @Log(title = "药品信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PharmacyDrug pharmacyDrug)
    {
        return toAjax(pharmacyDrugService.insertPharmacyDrug(pharmacyDrug));
    }

    /**
     * 修改药品信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:pharmacyDrug:edit')")
    @Log(title = "药品信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PharmacyDrug pharmacyDrug)
    {
        return toAjax(pharmacyDrugService.updatePharmacyDrug(pharmacyDrug));
    }

    /**
     * 删除药品信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:pharmacyDrug:remove')")
    @Log(title = "药品信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(pharmacyDrugService.deletePharmacyDrugByIds(ids));
    }
}